using UnityEngine;
using System.Collections;

//Class that manages sprite depths based on y axis to maintain proper z-axis draw order
public class DepthManagedSprite : MonoBehaviour {
	
	private float zDepthFactor = .001f;
	
	//Called on instantiation of this or any derived class
	protected virtual void Start () {
		updateDepthPosition();
	}
	
	//set this sprite's depth for appropriate draw order & scale
	public void updateDepthPosition() {
		transform.position = calcDepthPosition(transform.position);
		//This would dynamically scale the sprite based on y position so it looks like they're going 
			//"into" the scene
		//transform.localScale = calcDepthScale(transform.position, transform.localScale);
	}
	
	//returns the new scale vector based on depth so objects shrink as they go farther away
	public Vector3 calcDepthScale(Vector3 position, Vector3 scale) {
		//!! Find a way to do this without it changing whenever the screen is changing size...
			Debug.Log (position.y + " " + Screen.height);
		return scale;		
	}
	
	//Calculate the object's position so the depth is managed properly for draw order
	public Vector3 calcDepthPosition(Vector3 position) {
		position.z = position.y * zDepthFactor;
		return position;
	}
	
	public Vector3 getPosition() 
	{
		return transform.position;
	}
}
